﻿using System;
using System.Activities;
using ActivityLibrary;
using System.Collections.Generic;
using ClassLibrary;

namespace Web
{
    public partial class index : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnOK_Click(object sender, EventArgs e)
        {
            try
            {
                clsCalculator objCalc = new clsCalculator()
                   {
                       Number1 = Convert.ToDouble(txtNumero1.Text),
                       Number2 = Convert.ToDouble(txtNumero2.Text)
                   };

                switch (cmbOperacao.SelectedValue)
                {
                    case "SUM": objCalc.Operation = enOperations.SUM; break;
                    case "SUB": objCalc.Operation = enOperations.SUB; break;
                    case "DIV": objCalc.Operation = enOperations.DIV; break;
                    case "MUL": objCalc.Operation = enOperations.MUL; break;
                    case "POW": objCalc.Operation = enOperations.POW; break;
                }

                //Invoke Workflow with a dictonary for pass values
                var result = WorkflowInvoker.Invoke(new CalcActivity(), new Dictionary<string, object>() { { "objCalculator", objCalc } });

                //Receive a array with result
                lblResult.Text = result["douReturn"].ToString();
            }
            catch (Exception ex)
            {
                lblResult.Text = ex.Message;
            }

        }
    }
}